package com.wnxy.eleba.controller;

import com.github.pagehelper.PageInfo;
import com.wnxy.eleba.entity.Sj;
import com.wnxy.eleba.service.SjService_zhuying;
import com.wnxy.eleba.utils.Result;
import com.wnxy.eleba.vo.SjQueryParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商家控制器
 */

@CrossOrigin
@RestController
@RequestMapping("/sj")
public class SjController_zhuying {

    private SjService_zhuying sjService;

    public final Logger logger = LoggerFactory.getLogger(SjController_zhuying.class);

    @Autowired
    public void setSjService(SjService_zhuying sjService) {
        this.sjService = sjService;
    }

    @PostMapping("/findAllSj")
    public Result findAllSj(){
        List<Sj> list = sjService.findAll();
        System.out.println(list);
        return Result.ok().data("list",list);

    }



    @PostMapping("/listSjPageByCondition")
    public Result listSjPageByCondition(@RequestBody SjQueryParam sjQueryParam){
        logger.warn(sjQueryParam.toString());
        PageInfo<Sj> pageInfo = sjService.listSjPageByCondition(sjQueryParam);
//        System.out.println(pageInfo);
        return Result.ok().data("pageInfo",pageInfo);
        //return Result.ok().data("total",pageInfo.getTotal()).data("list",pageInfo.getList()).data("pageSize",pageInfo.getPageSize());
    }

    @GetMapping("/findSjById")
    public Result findSjById(@RequestParam("sjId") Integer sjId){
        logger.warn("sjId:" + sjId);
        Sj sj = sjService.findSjById(sjId);
        return Result.ok().data("sj",sj);
    }

    @PostMapping("/save")
    public Result saveSj(@RequestBody Sj sj){
        logger.warn("save sj:" + sj);
        boolean result = sjService.saveSj(sj);
        logger.warn("save result:" + result);
        System.out.println(sj);
        return Result.ok().success(result);
    }

    @PostMapping("/update")
    public Result updateSj(@RequestBody Sj sj){
        boolean result = sjService.updateSj(sj);
        return Result.ok().success(result);
    }

    @PostMapping("/delete")
    public Result deleteSj(@RequestParam("ids")Integer... ids){
        boolean result = sjService.deleteSj(ids);
        System.out.println("2222");
        return Result.ok().success(result);
    }

    @GetMapping("/del")
    public Result delSj(@RequestParam("id")Integer id){
        boolean result = sjService.delSj(id);
        System.out.println("2222");
        return Result.ok().success(result);
    }


    @GetMapping("/listsjType")
    public Result listsjType(){
        List<String> list = sjService.listsjType();
//        System.out.println("999999999");
//        System.out.println(list);

        return Result.ok().data("list",list);
    }

}
